package com.carlinfo.userscenter.common.util;

public class PageInfoUtil
{
	private int totalRecord;
	private int pageSize = 10;
	private int totalPage;
	private int currentPage;
	private int prePage;
	private int nextPage;
	private int currentRecord;

	public int getTotalRecord()
	{
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord)
	{
		this.totalRecord = totalRecord;
	}

	public int getPageSize()
	{
		return pageSize;
	}

	public void setPageSize(int pageSize)
	{
		this.pageSize = pageSize;
	}

	public int getCurrentPage()
	{
		if(this.currentPage < 1)
		{
			this.currentPage = 1 ; 
		}

		if(this.currentPage > this.getTotalPage())
		{
			this.currentPage = this.getTotalPage() ; 
		}
		return currentPage;
	}

	public void setCurrentPage(int currentPage)
	{
		this.currentPage = currentPage;
	}

	public int getTotalPage()
	{
		if(this.getTotalRecord() % this.getPageSize() == 0 )
		{
			this.totalPage = this.getTotalRecord() / this.getPageSize() ; 
		}else
		{
			this.totalPage = this.getTotalRecord() / this.getPageSize() + 1; 
		}
		if(this.totalPage == 0 )
		{
			this.totalPage = 1 ; 
		}
		return totalPage;
	}

	public int getPrePage()
	{
		this.prePage = this.getCurrentPage() - 1 ; 
		
		if(this.prePage < 1)
		{
			this.prePage = 1 ; 
		}
		return prePage;
	}

	public int getNextPage()
	{
		this.nextPage = this.getCurrentPage() + 1 ; 
		
		if(this.nextPage > this.getTotalPage())
		{
			this.nextPage = this.getTotalPage() ; 
		}
		return nextPage;
	}

	public int getCurrentRecord()
	{
		this.currentRecord = (this.getCurrentPage() - 1) * this.getPageSize(); 
		return currentRecord;
	}
	
	@Override
	public String toString()
	{
		return "PageInfoUtil [totalRecord=" + this.getTotalRecord() + ", pageSize=" + this.getPageSize() + ", totalPage=" + this.getTotalPage()
				+ ", currentPage=" + this.getCurrentPage() + ", prePage=" + this.getPrePage() + ", nextPage=" + this.getNextPage()
				+ ", currentRecord=" + this.getCurrentRecord() + "]";
	}
	
	public static void main(String[] args)
	{
		PageInfoUtil pageInfoUtil = new PageInfoUtil() ; 
		pageInfoUtil.setPageSize(5);
		pageInfoUtil.setCurrentPage(11111);
		System.out.println("--->" + pageInfoUtil);
	}
}
